Imports Microsoft.VisualBasic



Namespace Persistencia.ModuloPrincipal

    Public Class ControladorPersistencia
#Region "Atributos"
        Private Shared instance As ControladorPersistencia
        Private query As String
        Private BD As Persistencia.ModuloPrincipal.bd
#End Region
        'Constructor Vacio
        Public Sub New()
            BD = Persistencia.ModuloPrincipal.bd.getInstance
        End Sub

#Region "getInstance"
        'Patron Singleton 
        Public Shared Function getInstance() As ControladorPersistencia

            If instance Is Nothing Then
                instance = New ControladorPersistencia
            End If

            Return instance

        End Function
#End Region

#Region "funciones"

        Public Function ObtenerUsuario(ByVal Usuario As Usuario) As Boolean

            Dim Result As New ArrayList

            query = "select * from usuariosistema where usuario='" + Usuario.User + "' and password='" + Usuario.Password + "'"

            Result = BD.ObtenerUsuario(query)

            If Result.Count <> 0 Then
                Return True
            Else
                Return False
            End If

        End Function

        Public Function ObtenerUsuario(ByVal userId As String) As ArrayList
            Dim query As String = "select * from usuariosistema where usuario='" + userId + "'"
            Return BD.ObtenerUsuario(query)
        End Function

        Public Function ObtenerGrupo(ByVal id As String) As ArrayList
            Dim query As String = "select * from grupousuarios where id=" + id
            Return BD.ObtenerGrupo(query)
        End Function

        Public Function obtenerEmpleado(ByVal fk As String) As ArrayList
            Dim query As String = "select * from empleado where rut ='" + fk + "'"
            Return BD.obtenerEmpleado(query)
        End Function

        Public Function ObtenerDato(ByVal query As String) As Hashtable
            Return BD.EjecutarConRetorno(query)
        End Function

#End Region

    End Class
End Namespace

